package class91To100;

import java.io.*;

public class QuickPow {
    public static long a, b, p;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            a = (long) in.nval;
            in.nextToken();
            b = (long) in.nval;
            in.nextToken();
            p = (long) in.nval;
            out.println(a + "^" + b + " mod " + p + "=" + solve());
        }
        out.flush();
        out.close();
        br.close();
    }

    public static int solve() {
        long ans = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                ans = (ans * a) % p;
            }
            a = (a * a) % p;
            b >>= 1;
        }
        return (int) ans;
    }
}
